package c2.cross.business.championrace.temp;

import cate.game.framework.index.IndexedList;
import cate.game.pvp.championrace.data.ChampionRaceSpec;
import cate.game.pvp.championrace.data.ChampionRaceVideo;
import org.apache.commons.compress.utils.Lists;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.Map;

public class ChampionRaceTempVideoData extends IndexedList<String, ChampionRaceVideo> {

    public void upsert(ChampionRaceSpec spec, ChampionRaceVideo video) {
        addValue(video);
        addIndex(spec.toString(), video.getUid(), video);
    }

    public List<ChampionRaceVideo> query(ChampionRaceSpec spec) {
        Map<String, ChampionRaceVideo> indexMap = getIndex(spec.toString());
        return CollectionUtils.isEmpty(indexMap)
                ? Lists.newArrayList()
                : Lists.newArrayList(indexMap.values().iterator());
    }
}
